<template>
    <div class="order-list" v-loading="loading">
        <div class="input-box">
            <span class="input-title" style="margin-left: 0">开始时间</span>
            <el-date-picker
                v-model="dataValue"
                type="daterange"
                align="right"
                unlink-panels
                :clearable="false"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                @change="toDateChange"
                :picker-options="pickerOptions">
            </el-date-picker>
        </div>
        <div class="table-box">
            <el-table :data="tableData" ref="table" border :load="load" lazy :tree-props="{children: 'children', hasChildren: 'month'}" row-key="id" style="width: 100%">
                <el-table-column min-width="150" prop="month" label="时间">
                    <template slot-scope="scope">{{ tableFormatDate(scope.row.month) }}</template>
                </el-table-column>
                <el-table-column label="游戏">
                    <template slot-scope="scope">
                        <span>{{ scope.row.gameName || '-' }}</span>
                    </template>
                </el-table-column>
                <el-table-column min-width="100" label="账号托管数" prop="accountManagerCount"></el-table-column>
                <el-table-column min-width="100" label="每日派单量" prop="createOrderCount"></el-table-column>
            </el-table>
        </div>

        <!-- <div class="tools">
            <el-pagination
                @size-change="sizeChange"
                @current-change="pageChange"
                :current-page="pageNum"
                :page-sizes="_pageSizes"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </div> -->
    </div>
</template>

<script>
import { formatDate } from '@/utils/utils'

export default {
    data () {
        return {
            dataValue: [new Date() - 13 * 24 * 60 * 60 * 1000, new Date()],
            paramsList: {
                fromDate: formatDate(new Date() - 13 * 24 * 60 * 60 * 1000, 'YYYY-MM-DD') + ' 23:59:59',
                toDate: formatDate(new Date(), 'YYYY-MM-DD') + ' 23:59:59'
            },
            pickerOptions: {
                disabledDate (time) {
                    return time.getTime() > Date.now()
                }
            },
            tableData: [],
            pageNum: 1,
            total: 0,
            loading: false
        }
    },
    created () {
        this.getList(this.pageNum)
    },
    methods: {
        // 获取列表
        async getList (pageNum) {
            if (this.loading) return
            this.pageNum = pageNum
            this.loading = true
            let params = {
                pageNum: pageNum,
                pageSize: 99999
            }
            params = Object.assign(params, this.paramsList)
            let res = await this.$http.get('/trade/selectAccountManagerData', {
                params
            })
            if (res.code === '0') {
                this.tableData = res.data
                res.data.forEach((item, index) => {
                    item.id = index + 1
                })
                this.total = res.count
            } else {
                this.$message({
                    type: 'error',
                    message: '系统异常，请稍后再试'
                })
            }
            this.loading = false
        },
        toDateChange (val) {
            this.paramsList.fromDate = formatDate(new Date(val[0]), 'YYYY-MM-DD') + ' 23:59:59'
            this.paramsList.toDate = formatDate(new Date(val[1]), 'YYYY-MM-DD') + ' 23:59:59'
            this.getList(1)
        },
        // // 页码切换
        // sizeChange (val) {
        //     this.pageNum = 1
        //     this.pageSize = val
        //     this.getList(1)
        // },
        // // 页容切换
        // pageChange (val) {
        //     this.pageNum = val
        //     this.getList(this.pageNum)
        // },
        tableFormatDate (timestamp, type = 'YYYY-MM-DD') {
            return formatDate(timestamp, type)
        },
        // 加载子数据
        load (tree, treeNode, resolve) {
            this.$http.get('/trade/selectAccountManagerDataByGameId', {
                params: {
                    pageNum: 1,
                    pageSize: 1,
                    fromDate: formatDate(tree.month, 'YYYY-MM-DD') + ' 00:00:00',
                    toDate: formatDate(tree.month, 'YYYY-MM-DD') + ' 23:59:59'
                }
            }).then(res => {
                res.data.map((item, index) => {
                    delete item.month
                    item.id = new Date(tree.month).getTime() / 10000 + index
                })
                resolve(res.data)
            })
        }
    }
}
</script>

<style lang="scss" scoped>
    .order-list {
        .input-box {
            margin-top: 10px;
            font-size: 13px;
            font-weight: 500;
            .input-title {
                margin: 0 10px 0 20px;
            }
            .btn {
                margin-top: 10px;
                margin-left: 10px;
            }
        }
        .table-box {
            margin: 20px 0;
            .cover {
                width: 80px;
                height: 80px;
                > img {
                    width: 100%;
                    height: 100%;
                }
            }
        }

        .tools {
            padding-right: 20px;
            display: flex;
            justify-content: flex-end;
        }
    }
</style>
